/**
 * 基础接口
 */
import { HttpRequestParams, HttpResponseResult } from '../base/HttpRequest';
import { HttpRequestConstants } from '../constants/HttpRequestConstants';
import { FetchService } from '../service/FetchService'
import { LogUtil } from '../utils/LogUtil';
const fetchService = new FetchService();

export const fetchPost = async (apiName: string, params: any, fields?: string) => {
  const requestParams: HttpRequestParams = {
    api_name: apiName,
    token: HttpRequestConstants.APP_TOKEN,
    params: params,
    fields: fields
  }
  try {
    const result: HttpResponseResult = await fetchService.post<HttpResponseResult>(requestParams);
    LogUtil.info(`fetchPost successeed. Data: ${JSON.stringify(result)}`);
    return result.data;
  } catch (err) {
    LogUtil.error(`fetchPost failed. Cause: ${JSON.stringify(err)}`);
    return null;
  }
}